package com.ruoyi.system.service.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.WaterUser;
import com.ruoyi.system.domain.vo.WaterUserMeterVO;
import com.ruoyi.system.mapper.WaterUserMapper;
import com.ruoyi.system.service.IWaterUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * 用户档案Service业务层处理
 *
 * @author ruoyi
 * @date 2025-09-22
 */
@Service
public class WaterUserServiceImpl implements IWaterUserService
{
    @Autowired
    private WaterUserMapper waterUserMapper;

    /**
     * 查询用户档案
     *
     * @param id 用户档案主键
     * @return 用户档案
     */
    @Override
    public WaterUser selectWaterUserById(Long id)
    {
        return waterUserMapper.selectWaterUserById(id);
    }

    @Override
    public WaterUser selectWaterUserByUserId(String userId) {
        return waterUserMapper.selectWaterUserByUserId(userId);
    }

    /**
     * 查询用户档案列表
     *
     * @param waterUser 用户档案
     * @return 用户档案
     */
    @Override
    public List<WaterUser> selectWaterUserList(WaterUser waterUser)
    {
        return waterUserMapper.selectWaterUserList(waterUser);
    }

    /**
     * 新增用户档案
     *
     * @param waterUser 用户档案
     * @return 结果
     */
    @Override
    public int insertWaterUser(WaterUser waterUser)
    {
        waterUser.setCreateTime(DateUtils.getNowDate());
        return waterUserMapper.insertWaterUser(waterUser);
    }

    /**
     * 修改用户档案
     *
     * @param waterUser 用户档案
     * @return 结果
     */
    @Override
    public int updateWaterUser(WaterUser waterUser)
    {
        waterUser.setUpdateTime(DateUtils.getNowDate());
        return waterUserMapper.updateWaterUser(waterUser);
    }

    /**
     * 批量删除用户档案
     *
     * @param ids 需要删除的用户档案主键
     * @return 结果
     */
    @Override
    public int deleteWaterUserByIds(Long[] ids)
    {
        return waterUserMapper.deleteWaterUserByIds(ids);
    }

    /**
     * 删除用户档案信息
     *
     * @param id 用户档案主键
     * @return 结果
     */
    @Override
    public int deleteWaterUserById(Long id)
    {
        return waterUserMapper.deleteWaterUserById(id);
    }


    @Override
    public List<WaterUser> getWaterUserListPage(String depid, String userid, String username, String useraddress, String meterNo, Integer beginSize, Integer endSize) {


        return waterUserMapper.getWaterUserListPage(depid,userid,username,useraddress,meterNo, beginSize, endSize);
    }

    @Override
    public List<WaterUserMeterVO> selectWaterUserMeterList(WaterUserMeterVO userMeterVO) {
        return waterUserMapper.selectWaterUserMeterList(userMeterVO);
    }

    @Override
    public String getMaxUserId() {
        String maxUserId = waterUserMapper.getMaxUserId();
        Date time = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        String dateTime = sdf.format(time);
        if (StringUtils.isEmpty(maxUserId)) {
            maxUserId = dateTime + "001";
        } else {
            Long ins = Long.valueOf(maxUserId);
            ins = ins + 1;
            maxUserId = ins.toString();
        }
        return maxUserId;
    }

}
